﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

namespace Sharebert.OverlayLibrary
{
    public class Tools
    {
        /// <summary>
        /// Calculates a 16bit hash value of the given key
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static BigInteger Hash42(byte[] key)
        {
            BigInteger hash = new BigInteger(42);
            int sign = 0;
            foreach (char c in key)
            {

                hash = hash * (c + 42);
                hash = hash % (65536 + sign);
                if (sign == 0)
                {
                    sign = -1;
                }
                else
                {
                    sign = 0;
                }
            }
            return hash;
        }
    }
}
